package org.practice.service;

import java.beans.Introspector;

import org.junit.Test;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;

public class BeanNameGenerator extends AnnotationBeanNameGenerator {

	public BeanNameGenerator() {
	}
	
	protected String buildDefaultBeanName(BeanDefinition definition) {
		//org.jmock.practice.model.Company-->model_company
		String className = definition.getBeanClassName();
		String names[] = className.split("\\.");
		int len = names.length;
		return (new StringBuilder()).append(names[len - 2]).append("_")
				.append(Introspector.decapitalize(names[len - 1])).toString();
	}
}
